﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.Core.Exceptions;
using Enterprise.Framework.DomainModel.Repositories;

namespace Resto.CostControl.Core.Domain.Query.SupplierModule
{

    internal class SupplierDQO : IDomainQueryObject
    {
        public Supplier GetSupplier(string id)
        {
            Supplier order = GetSupplierOrDefault(id);

            if (order == null)
                throw new BusinessException("指定Id的供应商不存在");

            return order;
        }

        public Supplier GetSupplierOrDefault(string id)
        {
            IEntityRepository<Supplier> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<Supplier>();
            Supplier order = repository.Objects.Where(p => p.ID == id).FirstOrDefault();

            return order;
        }

        //public int[] GetAllSupplierId()
        //{
        //    IEntityRepository<Supplier> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<Supplier>();
        //    var list = from o in repository.Objects
        //                where o.IsDelete == false
        //                select o.ID;

        //    return list.ToArray();
        //}
    }
 

}
